import { useModel } from "umi";
import { useReactive } from "ahooks";

const useCategoryApplications = () => {
    const { remoteData } = useModel("global");

    const state = useReactive({
        loading: false,
        applications: [],
    });

    const loadCategoryApplications = async (pacName) => {
        state.loading = true;
        let res = await remoteData({
            object: "bnt-application-operation-center-service",
            serviceName: "/developer/person/application/getCategoryApplications",
            params: {
                pacName,
                order: [["appName", "ASC"]],
            },
        });
        state.applications = res || [];
        state.loading = false;
    };

    return { ...state, loadCategoryApplications };
};

export default useCategoryApplications;
